<?php
namespace app;

use think\App;
use app\BaseController;
use think\facade\Session;

abstract class User extends BaseController
{
    /**
     * 授权token
     * @var string
     */
    protected $auth_token;

    /**
     * csrf token
     * @var string
     */
    protected $csrf_token;

    /**
     * 用户id
     */
    protected $member_id;

    /**
     * 当前店铺id
     */
    protected $store_id = 0;

    public function __construct( App $app )
    {
        $this->member_id = Session::get( 'member_id' ); //用户id
        $this->store_id = Session::get( 'store_id' );   //当前店铺id

        parent::__construct( $app );
    }

    /**
     * 响应输出
     * @param array $data 响应数据
     * @return string
     */
    public function response( $data )
    {
        return json( [ 'code' => 0, 'message' => 'ok', 'result' => $data, 'csrf_token' => token( '_csrf_token' ) ] );
    }
}
